<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="userName">
    <input type="button" value="设置数据" id="setData">
    <input type="button" value="获取数据" id="getData">
    <input type="button" value="删除数据" id="removeData">
    <script>
        document.querySelector("#setData").onclick = function() {
            var name = document.querySelector("#userName").value;
            window.localStorage.setItem("userName", name);
        }
        document.querySelector("#getData").onclick = function() {
            var names = window.localStorage.getItem("userName");
            alert(names);
        }
        document.querySelector("#removeData").onclick = function() {
            window.localStorage.removeItem("id");
        }
    </script>
</body>

</html>